#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
#include <QtOpenGL>
#include <QPushButton>
#include <mycallback.h>
#include <zlib.h>

class GLWidget : public QGLWidget
{
    Q_OBJECT
public:
    explicit GLWidget(MyCallback* myCallback_, QWidget *parent = 0);
    QBasicTimer *timer;
    double getError();

private:
    void paintGL ();
    void initializeGL ();
    void resizeGL(int w, int h);
    void timerEvent(QTimerEvent *e);

    //Interaction
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent *event);

    void generatePath();
    void setUI();
    void setDifficulty();
    void saveData();

private:

    MyCallback* myCallback;
    double aspectRatio;
    QPoint dragLastPosition;
    QPoint dragStartPosition;
    bool dragging;
    qreal dragX;
    qreal dragY;
    QTimer* moveTimer;

    QPainterPath path;
    QRect fingerAreaRect;
    QRect finger;
    int tempX;

    int lastPointIndex;

    int difficultyLevel;

    int fingerX;
    int fingerY;
    int fingerRadius;

    int trialDuration;

    int yDelta;

    QString username;
    QString description;

    int w;
    int h;
    double trialProgress;

    int noSegments;
    int baseXDelta;

    double targetDistance;
    double errorScore;
    double errorViz;

    double fps;
    double framesCollected;
    long startFpsTime;
    int pathYLength;
    int pathYBegin;

    int pause;
    int pathGenerated;

    int inPathOnset;
    int inPathOffset;
    int inPathFinished;
    int inPathTrial;
    int baseYDelta;
    int minYDelta;

    int requestedFps;

    double speed;
    int totalFingerMovementX;
    int totalFingerMovementY;
    int lastFingerX;
    int lastFingerY;

    int screenNumber;
    QRect quitButtonRect;

    int frame;
    QVector<int>* fingerPositionVec;
    QVector<int>* pathPositionVec;

    QString pathString;
    QPainter* painter;

    QString tempString;

    QString fpsString;
    QString leftString;
    QString errorString;


signals:
    void finishGame();

public slots:
    void quit();
    void setUser(QString username_, QString description_);
    void setDifficultyLevel(int level);

    
};

#endif // GLWIDGET_H
